import { ref } from 'vue'

interface PaginationOptions {
  initialPageNum?: number
  initialPageSize?: number
}

export function usePagination(
  fetchData: () => Promise<void>,
  options: PaginationOptions = {}
) {
  const { initialPageNum = 1, initialPageSize = 10 } = options

  const pageNum = ref(initialPageNum)
  const pageSize = ref(initialPageSize)

  const onSizeChange = (size: number) => {
    pageSize.value = size
    fetchData()
  }

  const onCurrentChange = (page: number) => {
    pageNum.value = page
    fetchData()
  }

  return {
    pageNum,
    pageSize,
    onSizeChange,
    onCurrentChange
  }
}
